package com.gitee.huanminabc.demo.spring.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description: 拦截器
 * @Author huanmin
 * @Date 2024/6/5 上午10:47
 */
@Component
@Slf4j
public class DemoInterceptor implements HandlerInterceptor {
    //请求处理前
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        log.info("请求处理前");
        return true;
    }
    //请求处理后
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    }
    //请求处理完毕 ,这个和postHandle有点类似,但是这个是在整个请求处理完毕后调用的,也就是在DispatcherServlet渲染了对应的视图之后执行
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//        log.info("请求处理完毕");
    }


}
